<%-- 
    Document   : test
    Created on : Sep 9, 2011, 4:29:14 AM
    Author     : northpole
--%>

<%@page import="java.util.ArrayList"%>
<%@page import="user.User" contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <%User userInfo=null;%>
        <% if (request.getParameter("username").equals(session.getAttribute("username"))) {//re-visit own profile
               userInfo = (User) session.getAttribute("userInfo");%>
    </head>
    <body>

        <h1>Hello World!</h1>
        <%
            if (!session.getAttribute("username").equals("Visitor")) {
                out.println("your personal info</br>");

                out.println("id " + session.getAttribute("id") + " </br>");
                out.println(" name " + session.getAttribute("name") + "</br>");
                out.println(" surname " + session.getAttribute("surname") + "</br>");
                out.println(" interests " + session.getAttribute("interests") + "</br>");
                out.println(" Username " + session.getAttribute("username") + "</br>");
                out.println(" Password " + session.getAttribute("password") + "</br>");
                out.println(" welcome TEXT " + session.getAttribute("welcomeText") + "</br>");
                out.println(" U WERE BORN " + session.getAttribute("dateOfBirth") + "</br>");

                /*String[] friends = userInfo.getFriends();
                out.println("Your Friends are </br>");
                for (int i = 0; i < friends.length; i++) {
                    out.println("<a href=visitProfile.jsp?username=" + friends[i] + ">" + friends[i] + "</a></br>");
                }
               */
               ArrayList friends=(ArrayList)session.getAttribute("friends");
               out.println("Your Friends are </br>");
               for(int i=0;i<friends.size();i++){
               out.println("<a href=visitProfile.jsp?username=" + friends.get(i) + ">" + friends.get(i) + "</a></br>");
               }
               
                out.print("You should be friends with</br>");
                String[] suggestions = userInfo.SuggestFriends();
                for (int i = 0; i < suggestions.length; i++) {
                    out.print("<a href=visitProfile.jsp?username=" + suggestions[i] + ">" + suggestions[i] + "</a></br>");
                }
        %>
        <a href="editProfile.jsp"> Edit Profile </a>
        <a href="endSession.jsp">logout</a>
        
        
        <%
                    }
                }%>

                <% else if(!request.getParameter("username").equals(session.getAttribute("username"))){//visit not own profile
                        if(userInfo!=null && userInfo.isFriend(request.getParameter("username"))) //visiting a friend
                         {User friend=new User();
                          friend.setUsername(request.getParameter("username"));
                          friend.loadFriendInfo();
                          ArrayList inf=friend.getFriendInfo();
                          out.print("Name"+inf.get(0)+"</br>");
                          out.print("surname"+inf.get(1)+"</br>");
                          out.print("dateofbirth"+inf.get(2)+"</br>");
                          out.print("interests"+inf.get(3)+"</br>");
                          out.print("welcomeText"+inf.get(4)+"</br>");
                        }
                        else if(userInfo!=null &&!userInfo.isFriend(request.getParameter("username")))//visiting a stranger
                        {User stranger=new User();
                         stranger.loadPublicInfo();
                         ArrayList inf=stranger.getPublicInfo();
                         if(inf.get(0)!=null)
                         out.print("Interests"+inf.get(0)+"</br>");
                        out.print("Welcome Text"+inf.get(1)+"</br>");
                        
                            if(!session.getAttribute("username").equals("Visitor") &&!userInfo.pendingReq(request.getParameter("username")))
                                //if he is signed in and there is not a pending request for that profile
                                //provide the add friend
                            {%>
                
        <a href="addFriend.jsp?username=<%out.print(request.getParameter("username"));%> ">addfriend</a>
        
        <%}
                        }
                }
           
    %>
<a href="visitProfile.jsp?username=northy">visit northy</a>
    </body>
</html>
